import time
from selenium import webdriver
from selenium.webdriver.common.by import By

# 第一种 普通方式
# 打开浏览器访问网址
driver = webdriver.Chrome()
driver.get("https://sahitest.com/demo/selectTest.htm")

# driver.find_element()
# webelement.find_element()   # 以标签的形式进行定位,那么定位的就是当前webelement的后代标签
time.sleep(2)
select = driver.find_element(By.ID, "s1")
select.find_element(By.XPATH, "//select[@id='s1']/option[2]").click()

# print(select.find_element(By.TAG_NAME, "option").get_attribute("outerHTML"))
# print(select.find_element(By.CSS_SELECTOR, "option").get_attribute("outerHTML"))
# print(select.find_element(By.CSS_SELECTOR, "select>option:nth-child(2)").get_attribute("outerHTML"))

# 退出浏览器
time.sleep(2)
driver.quit()